package com.example.demo.Common;
import lombok.Data;

//统一返回对象
@Data
public class AjaxResult {
    private  int code;
    private  String msg;
    private  Object data;
    //返回成功数据
    public  static  AjaxResult success(Object data){
        AjaxResult ajaxResult=new AjaxResult();
        ajaxResult.setCode(200);
        ajaxResult.setMsg("");
        ajaxResult.setData(data);
        return ajaxResult;
    }
    public  static  AjaxResult success(Object data,String msg){
        AjaxResult ajaxResult=new AjaxResult();
        ajaxResult.setCode(200);
        ajaxResult.setMsg(msg);
        ajaxResult.setData(data);
        return  ajaxResult;
    }
    //返回错误数据
    public  static  AjaxResult fail(int code,String msg){
        AjaxResult ajaxResult=new AjaxResult();
        ajaxResult.setCode(code);
        ajaxResult.setMsg(msg);
        ajaxResult.setData("");
        return ajaxResult;
    }
    public  static  AjaxResult fail(int code,String msg,Object data){
        AjaxResult ajaxResult=new AjaxResult();
        ajaxResult.setCode(code);
        ajaxResult.setMsg(msg);
        ajaxResult.setData(data);
        return ajaxResult;
    }
}
